<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/doc/src/qset.qdoc -->
<head>
  <title>Qt 4.3: QSet::iterator Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QSet::iterator Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1>
<p>The QSet::iterator class provides an STL-style non-const iterator for <a href="qset.html">QSet</a>. <a href="#details">More...</a></p>
<pre> #include &lt;<a href="qset.html">QSet</a>&gt;</pre><p>This class was introduced in Qt 4.2.</p>
<ul>
<li><a href="qset-iterator-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qset-iterator.html#iterator">iterator</a></b> ()</li>
<li><div class="fn"/><b><a href="qset-iterator.html#iterator-3">iterator</a></b> ( const iterator &amp; <i>other</i> )</li>
<li><div class="fn"/>bool <b><a href="qset-iterator.html#operator-not-eq">operator!=</a></b> ( const iterator &amp; <i>other</i> ) const</li>
<li><div class="fn"/>bool <b><a href="qset-iterator.html#operator-not-eq-2">operator!=</a></b> ( const const_iterator &amp; <i>other</i> ) const</li>
<li><div class="fn"/>const T &amp; <b><a href="qset-iterator.html#operator-2a">operator*</a></b> () const</li>
<li><div class="fn"/>iterator <b><a href="qset-iterator.html#operator-2b">operator+</a></b> ( int <i>j</i> ) const</li>
<li><div class="fn"/>iterator &amp; <b><a href="qset-iterator.html#operator-2b-2b">operator++</a></b> ()</li>
<li><div class="fn"/>iterator <b><a href="qset-iterator.html#operator-2b-2b-2">operator++</a></b> ( int )</li>
<li><div class="fn"/>iterator &amp; <b><a href="qset-iterator.html#operator-2b-eq">operator+=</a></b> ( int <i>j</i> )</li>
<li><div class="fn"/>iterator <b><a href="qset-iterator.html#operator-">operator-</a></b> ( int <i>j</i> ) const</li>
<li><div class="fn"/>iterator &amp; <b><a href="qset-iterator.html#operator--">operator--</a></b> ()</li>
<li><div class="fn"/>iterator <b><a href="qset-iterator.html#operator---2">operator--</a></b> ( int )</li>
<li><div class="fn"/>iterator &amp; <b><a href="qset-iterator.html#operator--eq">operator-=</a></b> ( int <i>j</i> )</li>
<li><div class="fn"/>const T * <b><a href="qset-iterator.html#operator--gt">operator-&gt;</a></b> () const</li>
<li><div class="fn"/>iterator &amp; <b><a href="qset-iterator.html#operator-eq">operator=</a></b> ( const iterator &amp; <i>other</i> )</li>
<li><div class="fn"/>bool <b><a href="qset-iterator.html#operator-eq-eq">operator==</a></b> ( const iterator &amp; <i>other</i> ) const</li>
<li><div class="fn"/>bool <b><a href="qset-iterator.html#operator-eq-eq-2">operator==</a></b> ( const const_iterator &amp; <i>other</i> ) const</li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QSet::iterator class provides an STL-style non-const iterator for <a href="qset.html">QSet</a>.</p>
<p><a href="qset.html">QSet</a> features both <a href="containers.html#stl-style-iterators">STL-style iterators</a> and <a href="containers.html#java-style-iterators">Java-style iterators</a>. The STL-style iterators are more low-level and more cumbersome to use; on the other hand, they are slightly faster and, for developers who already know STL, have the advantage of familiarity.</p>
<p><a href="qset.html">QSet</a>&lt;T&gt;::iterator allows you to iterate over a <a href="qset.html">QSet</a> and to remove items (using <a href="qset.html#erase">QSet::erase</a>()) while you iterate. (<a href="qset.html">QSet</a> doesn't let you <i>modify</i> a value through an iterator, because that would potentially require moving the value in the internal hash table used by <a href="qset.html">QSet</a>.) If you want to iterate over a const <a href="qset.html">QSet</a>, you should use <a href="qset-const-iterator.html">QSet::const_iterator</a>. It is generally good practice to use <a href="qset-const-iterator.html">QSet::const_iterator</a> on a non-const <a href="qset.html">QSet</a> as well, unless you need to change the <a href="qset.html">QSet</a> through the iterator. Const iterators are slightly faster, and can improve code readability.</p>
<p><a href="qset.html">QSet</a>&lt;T&gt;::iterator allows you to iterate over a <a href="qset.html">QSet</a>&lt;T&gt; and modify it as you go (using <a href="qset.html#erase">QSet::erase</a>()). However,</p>
<p>The default QSet::iterator constructor creates an uninitialized iterator. You must initialize it using a function like <a href="qset.html#begin">QSet::begin</a>(), <a href="qset.html#end">QSet::end</a>(), or <a href="qset.html#insert">QSet::insert</a>() before you can start iterating. Here's a typical loop that prints all the items stored in a set:</p>
<pre> QSet&lt;QString&gt; set;
 set &lt;&lt; &quot;January&quot; &lt;&lt; &quot;February&quot; &lt;&lt; ... &lt;&lt; &quot;December&quot;;

 QSet&lt;QString&gt;::iterator i;
 for (i = set.begin(); i != set.end(); ++i)
     qDebug() &lt;&lt; *i;</pre>
<p>Here's a loop that removes certain items (all those that start with 'J') from a set while iterating:</p>
<pre> QSet&lt;QString&gt; set;
 set &lt;&lt; &quot;January&quot; &lt;&lt; &quot;February&quot; &lt;&lt; ... &lt;&lt; &quot;December&quot;;

 QSet&lt;QString&gt;::iterator i = set.begin();
 while (i != set.end()) {
     if ((*i).startsWith('J')) {
         i = set.erase(i);
     } else {
         ++i;
     }
 }</pre>
<p>STL-style iterators can be used as arguments to <a href="qtalgorithms.html">generic algorithms</a>. For example, here's how to find an item in the set using the <a href="qtalgorithms.html#qFind">qFind</a>() algorithm:</p>
<pre> QSet&lt;QString&gt; set;
 ...
 QSet&lt;QString&gt;::iterator it = qFind(set.begin(), set.end(), &quot;Jeanette&quot;);
 if (it != set.end())
     cout &lt;&lt; &quot;Found Jeanette&quot; &lt;&lt; endl;</pre>
<p>Multiple iterators can be used on the same set. However, you may not attempt to modify the container while iterating on it.</p>
<p>See also <a href="qset-const-iterator.html">QSet::const_iterator</a> and <a href="qmutablesetiterator.html">QMutableSetIterator</a>.</p>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="iterator"></a>iterator::iterator ()</h3>
<p>Constructs an uninitialized iterator.</p>
<p>Functions like operator*() and operator++() should not be called on an uninitialized iterator. Use operator=() to assign a value to it before using it.</p>
<p>See also <a href="qset.html#begin">QSet::begin</a>() and <a href="qset.html#end">QSet::end</a>().</p>
<h3 class="fn"><a name="iterator-3"></a>iterator::iterator ( const iterator &amp; <i>other</i> )</h3>
<p>Constructs a copy of <i>other</i>.</p>
<h3 class="fn"><a name="operator-not-eq"></a>bool iterator::operator!= ( const iterator &amp; <i>other</i> ) const</h3>
<p>Returns true if <i>other</i> points to a different item than this iterator; otherwise returns false.</p>
<p>See also <a href="qset-iterator.html#operator-eq-eq">operator==</a>().</p>
<h3 class="fn"><a name="operator-not-eq-2"></a>bool iterator::operator!= ( const <a href="qset-const-iterator.html">const_iterator</a> &amp; <i>other</i> ) const</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<h3 class="fn"><a name="operator-2a"></a>const T &amp; iterator::operator* () const</h3>
<p>Returns a reference to the current item.</p>
<p>See also <a href="qset-iterator.html#operator--gt">operator-&gt;</a>().</p>
<h3 class="fn"><a name="operator-2b"></a>iterator iterator::operator+ ( int <i>j</i> ) const</h3>
<p>Returns an iterator to the item at <i>j</i> positions forward from this iterator. (If <i>j</i> is negative, the iterator goes backward.)</p>
<p>This operation can be slow for large <i>j</i> values.</p>
<p>See also <a href="qset-iterator.html#operator-">operator-</a>().</p>
<h3 class="fn"><a name="operator-2b-2b"></a>iterator &amp; iterator::operator++ ()</h3>
<p>The prefix ++ operator (<tt>++it</tt>) advances the iterator to the next item in the set and returns an iterator to the new current item.</p>
<p>Calling this function on <a href="qset.html#constEnd">QSet::constEnd</a>() leads to undefined results.</p>
<p>See also <a href="qset-iterator.html#operator--">operator--</a>().</p>
<h3 class="fn"><a name="operator-2b-2b-2"></a>iterator iterator::operator++ ( int )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>The postfix ++ operator (<tt>it++</tt>) advances the iterator to the next item in the set and returns an iterator to the previously current item.</p>
<h3 class="fn"><a name="operator-2b-eq"></a>iterator &amp; iterator::operator+= ( int <i>j</i> )</h3>
<p>Advances the iterator by <i>j</i> items. (If <i>j</i> is negative, the iterator goes backward.)</p>
<p>This operation can be slow for large <i>j</i> values.</p>
<p>See also <a href="qset-iterator.html#operator--eq">operator-=</a>() and <a href="qset-iterator.html#operator-2b">operator+</a>().</p>
<h3 class="fn"><a name="operator-"></a>iterator iterator::operator- ( int <i>j</i> ) const</h3>
<p>Returns an iterator to the item at <i>j</i> positions backward from this iterator. (If <i>j</i> is negative, the iterator goes forward.)</p>
<p>This operation can be slow for large <i>j</i> values.</p>
<p>See also <a href="qset-iterator.html#operator-2b">operator+</a>().</p>
<h3 class="fn"><a name="operator--"></a>iterator &amp; iterator::operator-- ()</h3>
<p>The prefix -- operator (<tt>--it</tt>) makes the preceding item current and returns an iterator to the new current item.</p>
<p>Calling this function on <a href="qset.html#begin">QSet::begin</a>() leads to undefined results.</p>
<p>See also <a href="qset-iterator.html#operator-2b-2b">operator++</a>().</p>
<h3 class="fn"><a name="operator---2"></a>iterator iterator::operator-- ( int )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>The postfix -- operator (<tt>it--</tt>) makes the preceding item current and returns an iterator to the previously current item.</p>
<h3 class="fn"><a name="operator--eq"></a>iterator &amp; iterator::operator-= ( int <i>j</i> )</h3>
<p>Makes the iterator go back by <i>j</i> items. (If <i>j</i> is negative, the iterator goes forward.)</p>
<p>This operation can be slow for large <i>j</i> values.</p>
<p>See also <a href="qset-iterator.html#operator-2b-eq">operator+=</a>() and <a href="qset-iterator.html#operator-">operator-</a>().</p>
<h3 class="fn"><a name="operator--gt"></a>const T * iterator::operator-&gt; () const</h3>
<p>Returns a pointer to the current item.</p>
<p>See also <a href="qset-iterator.html#operator-2a">operator*</a>().</p>
<h3 class="fn"><a name="operator-eq"></a>iterator &amp; iterator::operator= ( const iterator &amp; <i>other</i> )</h3>
<p>Assigns <i>other</i> to this iterator.</p>
<h3 class="fn"><a name="operator-eq-eq"></a>bool iterator::operator== ( const iterator &amp; <i>other</i> ) const</h3>
<p>Returns true if <i>other</i> points to the same item as this iterator; otherwise returns false.</p>
<p>See also <a href="qset-iterator.html#operator-not-eq">operator!=</a>().</p>
<h3 class="fn"><a name="operator-eq-eq-2"></a>bool iterator::operator== ( const <a href="qset-const-iterator.html">const_iterator</a> &amp; <i>other</i> ) const</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
